package com.ty.util;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import com.ty.mybatis.entity.Types;

public class TypesUtil implements Serializable {

	/**
	 * serialVersionUID : 
	 */ 
	private static final long serialVersionUID = -3604172179683369792L;
	
	public static final Map<String, Types> typeMap = new HashMap<String, Types>(); 
	
	static {
		//数值类型
		typeMap.put("tinyint", new Types("TINYINT", "Byte", "java.lang.Byte"));
		typeMap.put("smallint", new Types("SMALLINT", "Integer", "java.lang.Integer"));
		typeMap.put("mediumint", new Types("INTEGER", "Integer", "java.lang.Integer"));
		typeMap.put("int", new Types("INTEGER", "Integer", "java.lang.Integer"));
		typeMap.put("integer", new Types("INTEGER", "Integer", "java.lang.Integer"));
		typeMap.put("bigint", new Types("BIGINT", "Long", "java.lang.Long"));
		typeMap.put("decimal", new Types("DECIMAL", "BigDecimal", "java.math.BigDecimal"));
		typeMap.put("numeric", new Types("DECIMAL", "BigDecimal", "java.math.BigDecimal"));
		typeMap.put("float", new Types("REAL", "Float", "java.lang.Float"));
		typeMap.put("double", new Types("DOUBLE", "Double", "java.lang.Double"));
		typeMap.put("real", new Types("DOUBLE", "Double", "java.lang.Double"));
		typeMap.put("bit", new Types("BIT", "Boolean", "java.lang.Boolean"));
		
		//字符类型
		typeMap.put("char", new Types("CHAR", "String", "java.lang.String"));
		typeMap.put("varchar", new Types("VARCHAR", "String", "java.lang.String"));
		typeMap.put("binary", new Types("BINARY", "Byte[]", "java.lang.Byte"));
		typeMap.put("varbinary", new Types("VARBINARY", "Byte[]", "java.lang.Byte"));
		typeMap.put("tinyblob", new Types("BINARY", "Byte[]", "java.lang.String"));
		typeMap.put("blob", new Types("LONGVARBINARY", "Byte[]", "java.lang.String"));
		typeMap.put("mediumblob", new Types("LONGVARBINARY", "Byte[]", "java.lang.String"));
		typeMap.put("longblob", new Types("LONGVARBINARY", "Byte[]", "java.lang.String"));
		typeMap.put("tinytext", new Types("LONGVARCHAR", "String", "java.lang.String"));
		typeMap.put("text", new Types("LONGVARCHAR", "String", "java.lang.String"));
		typeMap.put("mediumtext", new Types("LONGVARCHAR", "String", "java.lang.String"));
		typeMap.put("longtext", new Types("LONGVARCHAR", "String", "java.lang.String"));
		//enum=ENUM,
		//set=SET,
		
		//日期类型
		typeMap.put("date", new Types("DATE", "Date", "java.util.Date"));
		typeMap.put("datetime", new Types("TIMESTAMP", "Timestamp", "java.sql.Timestamp"));
		typeMap.put("time", new Types("TIME", "Time", "java.sql.Time"));
		typeMap.put("timestamp", new Types("TIMESTAMP", "Timestamp", "java.sql.Timestamp"));
		typeMap.put("year", new Types("YEAR", "Date", "java.util.Date"));
		//几何类型
		typeMap.put("geometry", new Types("BINARY", "Byte[]", "java.lang.Byte"));
		typeMap.put("geometrycollection", new Types("OTHER", "Object", "java.lang.Object"));
		typeMap.put("point", new Types("OTHER", "Object", "java.lang.Object"));
		typeMap.put("multipoint", new Types("OTHER", "Object", "java.lang.Object"));
		typeMap.put("linestring", new Types("OTHER", "Object", "java.lang.Object"));
		typeMap.put("multilinestring", new Types("OTHER", "Object", "java.lang.Object"));
		typeMap.put("polygon", new Types("OTHER", "Object", "java.lang.Object"));
		typeMap.put("multipolygon", new Types("OTHER", "Object", "java.lang.Object"));
	}
	
	public static String getJdbcType(String column) {
		return typeMap.get(column).getJdbcType();
	}
	
	public static String getJavaType(String column) {
		return typeMap.get(column).getJavaType();
	}
	
	public static String getJavaType2(String column) {
		return typeMap.get(column).getJavaType2();
	}

}
